﻿Imports System
Imports System.IO
Imports System.Data
Imports System.String
Imports System.Text
Imports IDServer

''' <summary>
'''     建立日期：2010-4-19
'''       建立者：JASON
'''   最后修改人：JASON
''' 最后修改日期：2010-4-19
'''         备注：
''' </summary>
''' <remarks></remarks>
''' 

Public Class Frm_BSCStaff

    Implements IDServer.IDServer.IDServer
    Public ActionHelp As IDServer.IDServer.ActionBtn = IDServer.IDServer.ActionBtn.ActionHelp
    Private mDataset As DataSet
    Private DeptDS As DataSet
    Public bFind As Boolean
    Public Fields As String
    Private WithEvents MainFrom As Frm_MainForm
    Private Captionstr As String = String.Empty
    Private Captionstr_CHT As String = "職員編號^fCode&中文名稱^fCName&英文名稱^fEName&所屬部門^fDeptID&職務^fPosition&性別^fSex&出生日期^fBirthday&教育程度^fEducation&婚姻狀況^fMarry&身份ID^fCardID&移動電話^fMobile&E--Mail^fEmail&MSN^fMSN&QQ^fQQ&家庭住址^fAddress&個人主頁^fPersonweb&住宅電話^fPhone&入職日期^fStartDate&離職日期^fEndDate&備注^fRemark&狀態^fStatus"
    Private Captionstr_CHS As String = "职员编号^fCode&中文名称^fCName&英文名称^fEName&所属部门^fDeptID&职务^fPosition&性别^fSex&出生日期^fBirthday&教育程度^fEducation&婚姻状况^fMarry&身份ID^fCardID&移动电话^fMobile&E--Mail^fEmail&MSN^fMSN&QQ^fQQ&家庭住址^fAddress&个人主页^fPersonweb&住宅电话^fPhone&入职日期^fStartDate&离职日期^fEndDate&备注^fRemark&状态^fStatus"
    Private Captionstr_en As String = "EmployeeID^fCode&Chinese Name^fCName&English Name ^fEName&Dept^fDeptID&Postion^fPosition&Sex^fSex&Birthday^fBirthday&Education Status^fEducation&Marry Status^fMarry&ID^fCardID&Mobile^fMobile&E--Mail^fEmail&MSN^fMSN&QQ^fQQ&Famliy Address^fAddress&Personal Website^fPersonweb&Family Phone^fPhone&Sine Date^fStartDate&End Date^fEndDate&Remark^fRemark&Status^fStatus"

    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainFrom
        End Get
        Set(ByVal value As Frm_MainForm)
            MainFrom = value
        End Set
    End Property

#Region "Variable Define"

    ''' <summary>
    ''' Is Loading Complete
    ''' </summary>
    ''' <remarks></remarks>
    Private LoadBool As Boolean = False

#End Region
#Region "Interface Define"

    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd
        If AddEnable = False Then
            MessageBox.Show(My.Resources.NotAllowAdd, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If

        If Me.TabControl1.SelectedIndex = 0 Then
            Me.TabControl1.SelectedIndex = 1
        End If
        ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd
        ClearText()
        SetCtlEnable(True)
        SetButton(ButtonType.Add, False)
        'MainFrom.BtnEnable(False)
        Me.txtfcode.Focus()
    End Function
    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel
        ClearText()
        SetCtlEnable(False)
        If Me.TabControl1.SelectedIndex = 0 Then
        Else
            If mDataset.Tables(0).Rows.Count <= 0 Then
                bFind = False
            Else
                FillText(Me.DataGridView1.CurrentRow.Cells("fCode").Value)
                bFind = True
            End If
        End If
        'MainFrom.BtnEnable(bFind)
        'GetToolEnable()

        SetButton(ButtonType.Browse, Me.DataGridView1.RowCount > 0)
        MainFrom.ToolStripFilter.Enabled = False
        MainFrom.ToolStripFind.Enabled = False

        ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
    End Function
    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete
        Try
            If DeleteEnable = False Then
                MessageBox.Show(My.Resources.NotAllowDelete, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
            If fCode.Length > 0 Then
                If MsgBox(My.Resources.ConfirmDelete, MsgBoxStyle.Question + MsgBoxStyle.OkCancel, Msg.CompanyName) = MsgBoxResult.Ok Then
                    If DeleteFromDataBase(fCode) = True And DeleteFromDataset(fCode) = True Then
                        MsgBox(My.Resources.DeleteSuccess, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                        Me.DataGridView1.DataSource = mDataset.Tables(0)
                        If Not Me.DataGridView1.CurrentRow Is Nothing Then
                            FillText(Me.DataGridView1.CurrentRow.Cells("fCode").Value)
                        Else
                            FillText("")
                        End If
                    End If
                End If
            End If
            GetToolEnable()
        Catch ex As Exception
            MsgBox("ActionDelete:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit
        Try
            If EditEnable = False Then
                MessageBox.Show(My.Resources.NotAllowEidt, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If

            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
            ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit
            SetCtlEnable(True)
            SetButton(ButtonType.Edit, False)
            Me.txtfcode.Enabled = False
            Me.txtfCName.Focus()
        Catch ex As Exception
            MsgBox("ActionEdit:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport
        Try
            If ExportEnable = False Then
                MessageBox.Show(My.Resources.NotAllowExport, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MsgBox("ActionExport:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter
        Try
            Dim Frm_Filter As New Frm_Filter
            Me.Cursor = Cursors.WaitCursor
            Frm_Filter.LoadHeaderCaption(Fields, "Frm_BSCStaff")
            Frm_Filter.ShowDialog()
            Me.Cursor = Cursors.Default
            ReBindGridCaption(Me.DataGridView1, "Frm_BSCStaff")
        Catch ex As Exception
            MsgBox("ActionFilter;" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst
        Try
            Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(0).Cells(0)
            MainFrom.ToolStripFirst.Enabled = False
            MainFrom.ToolStripNext.Enabled = True
            MainFrom.ToolStripPrivous.Enabled = False
            MainFrom.ToolStripLast.Enabled = True
            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
            If fCode.Length > 0 Then
                FillText(fCode)
            End If
        Catch ex As Exception
            MsgBox("ActionGoFirst:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast
        Try
            Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(Me.DataGridView1.RowCount - 1).Cells(0)
            MainFrom.ToolStripFirst.Enabled = True
            MainFrom.ToolStripNext.Enabled = False
            MainFrom.ToolStripPrivous.Enabled = True
            MainFrom.ToolStripLast.Enabled = False
            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
            If fCode.Length > 0 Then
                FillText(fCode)
            End If
        Catch ex As Exception
            MsgBox("ActionGoLast:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext
        Try

            Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index + 1).Cells(0)
            If Me.DataGridView1.CurrentRow.Index = Me.DataGridView1.RowCount - 1 Then
                MainFrom.ToolStripNext.Enabled = False
                MainFrom.ToolStripLast.Enabled = False
            Else
                MainFrom.ToolStripPrivous.Enabled = True
                MainFrom.ToolStripLast.Enabled = True
                MainFrom.ToolStripFirst.Enabled = True
                MainFrom.ToolStripNext.Enabled = True
            End If
            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
            If fCode.Length > 0 Then
                FillText(fCode)
            End If
        Catch ex As Exception
            MsgBox("ActionGoNext:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious
        Try
            Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index - 1).Cells(0)
            If Me.DataGridView1.CurrentRow.Index = 0 Then
                MainFrom.ToolStripFirst.Enabled = False
                MainFrom.ToolStripPrivous.Enabled = False
            Else
                MainFrom.ToolStripFirst.Enabled = True
                MainFrom.ToolStripNext.Enabled = True
                MainFrom.ToolStripPrivous.Enabled = True
                MainFrom.ToolStripLast.Enabled = True
            End If
            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
            If fCode.Length > 0 Then
                FillText(fCode)
            End If
        Catch ex As Exception
            MsgBox("ActionGoPrevious:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport
        Try
            If App.ImportEnable = False Then
                MessageBox.Show(My.Resources.NotAllowImport, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MsgBox("ImportEnable:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize
        Try
            If Me.txtfcode.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullEmployeeNo, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtfcode.Focus()
                Return False
            End If
            If Me.txtfCName.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullEmployeeCName, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.fCName.Focus()
                Return False
            End If
            If Me.txtfPosition.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullfPosition, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtfPosition.Focus()
                Return False
            End If
            If Me.CBfDeptID.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullfDeptId, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.CBfDeptID.Focus()
                SendKeys.Send("{F4}")
                Return False
            End If
            If Me.txtfBirthday.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullfBirthday, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtfBirthday.Focus()
                SendKeys.Send("{F4}")
                Return False
            Else
                If Not IsDate(Format(Me.txtfBirthday.Text, "yyyy-MM-dd")) Then
                    MsgBox(My.Resources.NotValidatefBirthday, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.txtfBirthday.Focus()
                    SendKeys.Send("{F4}")
                    Return False
                End If
            End If
            If Me.txtStartDate.Text.Length <= 0 Then
                MsgBox(My.Resources.NotNullfStartDate, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Me.txtfStartDate.Focus()
                SendKeys.Send("{F4}")
                Return False
            Else
                If Not IsDate(Format(Me.txtStartDate.Text, "yyyy-MM-dd")) Then
                    MsgBox(My.Resources.NotValidatefStartDate, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.txtfStartDate.Focus()
                    SendKeys.Send("{F4}")
                    Return False
                End If
            End If
            If Me.txtEndDate.Text.Length > 0 Then
                If Not IsDate(Format(Me.txtEndDate.Text, "yyyy-MM-dd")) Then
                    MsgBox(My.Resources.NotValidatefEndDate, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.txtfEndDate.Focus()
                    SendKeys.Send("{F4}")
                    Return False
                End If
                If CDate(Me.txtStartDate.Text) > CDate(Me.txtEndDate.Text) Then
                    MsgBox(My.Resources.NoGaffStartDate, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.txtfStartDate.Focus()
                    SendKeys.Send("{F4}")
                    Return False
                End If
            End If
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                Dim sql As String = ""
                Dim M_ds As New DataSet
                sql = "select fCode from BSC_Employee where fCode='" & Me.txtfcode.Text.Replace(",", "").Replace("'", "") & "'"
                M_ds = ReturnDataset(sql)
                If M_ds.Tables(0).Rows.Count > 0 Then
                    MsgBox(My.Resources.ExistSameEmployeeCode, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                    Me.txtfcode.Focus()
                    Me.txtfcode.SelectAll()
                    Return False
                End If
            End If
            Return True
        Catch ex As Exception
            MsgBox("ActionInitialize:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint

    End Function
    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave
        If BtnActionSave() = True Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect
        Me.Cursor = Cursors.WaitCursor
        ActionFind()
        Me.Cursor = Cursors.Default
    End Function
    Public Function ActionChecked() As Boolean
        If CheckEnable = False Then
            MessageBox.Show(My.Resources.NotAllowCheck, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If
        Return True
    End Function
    Public Function ActionUnchecked() As Boolean
        If CheckEnable = False Then
            MessageBox.Show(My.Resources.NotAllowUncheck, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Function
        End If
        Return True
    End Function
    Public Function ActionComplete() As Boolean
        Return True
    End Function

#End Region
#Region "sub or function Events"

    Private Function BuildDataset() As DataSet
        Try
            Dim M_Ds As New DataSet

            Dim mTable As New DataTable
            With mTable
                .Columns.Add("fCode", GetType(String))
                .Columns.Add("fCName", GetType(String))
                .Columns.Add("fEName", GetType(String))
                .Columns.Add("fPosition", GetType(String))
                .Columns.Add("fDeptId", GetType(String))
                .Columns.Add("fSex", GetType(String))
                .Columns.Add("fBirthday", GetType(String))
                .Columns.Add("fEducation", GetType(String))
                .Columns.Add("fMarry", GetType(String))
                .Columns.Add("fCardID", GetType(String))
                .Columns.Add("fMobile", GetType(String))
                .Columns.Add("fEmail", GetType(String))
                .Columns.Add("fMSN", GetType(String))
                .Columns.Add("fQQ", GetType(String))
                .Columns.Add("fAddress", GetType(String))
                .Columns.Add("fPersonweb", GetType(String))
                .Columns.Add("fPhone", GetType(String))
                .Columns.Add("fStartDate", GetType(String))
                .Columns.Add("fEndDate", GetType(String))
                .Columns.Add("fRemark", GetType(String))
                .Columns.Add("fStatus", GetType(String))
                .Columns.Add("fIsAdmin", GetType(String))
            End With
            M_Ds.Tables.Add(mTable)

            Return M_Ds
        Catch ex As Exception
            MsgBox("BuildDataset:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Private Sub SetCtlEnable(ByVal B As Boolean)
        Try
            Me.txtfAddress.Enabled = B
            Me.txtfBirthday.Enabled = B
            Me.txtfCardID.Enabled = B
            Me.txtfCName.Enabled = B
            Me.txtfcode.Enabled = B
            Me.txtfEducation.Enabled = B
            Me.txtfEducation.Enabled = B
            Me.txtfEmail.Enabled = B
            Me.txtfEName.Enabled = B
            Me.txtfEndDate.Enabled = B
            Me.txtfMarry.Enabled = B
            Me.txtfMobile.Enabled = B
            Me.txtfMSN.Enabled = B
            Me.txtfPhone.Enabled = B
            Me.txtfPosition.Enabled = B
            Me.txtfQQ.Enabled = B
            Me.txtfRemark.Enabled = B
            Me.txtfStartDate.Enabled = B
            Me.txtPersonweb.Enabled = B
            Me.CBfSex.Enabled = B
            Me.CBfDeptID.Enabled = B
            Me.txtStartDate.Enabled = B
            Me.txtEndDate.Enabled = B
            Me.txtfStatus.Enabled = B
            Me.cbAdmin.Enabled = B
            Me.BtnOK.Enabled = B
            Me.BtnCancel.Enabled = B
        Catch ex As Exception
            MsgBox("SetCtlEnable:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub ClearText()
        Try
            Me.txtfAddress.Text = ""
            Me.txtfBirthday.Text = ""
            Me.txtfCardID.Text = ""
            Me.txtfCName.Text = ""
            Me.txtfcode.Text = ""
            Me.txtfEducation.Text = ""
            Me.txtfEducation.Text = ""
            Me.txtfEmail.Text = ""
            Me.txtfEName.Text = ""
            Me.txtfEndDate.Text = ""
            Me.txtfMarry.Text = ""
            Me.txtfMobile.Text = ""
            Me.txtfMSN.Text = ""
            Me.txtfPhone.Text = ""
            Me.txtfPosition.Text = ""
            Me.txtfQQ.Text = ""
            Me.txtfRemark.Text = ""
            Me.txtStartDate.Text = ""
            Me.txtEndDate.Text = ""
            Me.txtfStartDate.Text = ""
            Me.txtPersonweb.Text = ""
            Me.txtfStatus.Checked = False
            Me.cbAdmin.Checked = False
        Catch ex As Exception
            MsgBox("ClearText:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub LoadComBox(ByVal ComBox As ComboBox)
        Try
            With ComBox


                Select Case str_language
                    Case "zh-CHS"
                        .Items.Add("<未选定>")
                        .Items.Add("男")
                        .Items.Add("女")
                    Case "zh-CHT"
                        .Items.Add("<未選定>")
                        .Items.Add("男")
                        .Items.Add("女")
                    Case "en"
                        .Items.Add("<Undefine>")
                        .Items.Add("male")
                        .Items.Add("female")
                End Select
            End With
            ComBox.SelectedIndex = 0
            ComBox.DropDownStyle = ComboBoxStyle.DropDownList
        Catch ex As Exception
            MsgBox("LoadComBox:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub LoadDeptID()
        Try
            Dim sql As String = ""
            sql = "select * from BSC_Dept where fDefine=1 ;"
            sql += "select * from BSC_Dept where fDefine=2"
            DeptDS = New DataSet
            DeptDS = ReturnDataset(sql)

            Me.CBfDeptID.DisplayMember = "fCName"
            Me.CBfDeptID.ValueMember = "ID"
            Me.CBfDeptID.DataSource = DeptDS.Tables(0)
            Me.CBfDeptID.Text = ""

            Me.fDeptID.DisplayMember = "fCName"
            Me.fDeptID.ValueMember = "ID"
            Me.fDeptID.DataSource = DeptDS.Tables(0)
            Me.fDeptID.Text = ""

            'Me.fDeptID.DropDownStyle = ComboBoxStyle.DropDownList
            'Me.CBfDeptID.DropDownStyle = ComboBoxStyle.DropDownList
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Private Sub ActionFind()
        Try
            Dim sql As String = ""
            Dim fCode As String = Me.fCode.Text.Replace("'", "")
            Dim fCName As String = Me.fCName.Text.Replace(",", "")
            Dim WhereStr As String = ""
            If Me.fCode.Text.Length > 0 Then
                WhereStr = " and a.fCode='" & Me.fCode.Text.Replace("'", "").Replace(",", "") & "'"
            End If
            If Me.fCName.Text.Length > 0 Then
                WhereStr += " and a.fCName='" & Me.fCName.Text.Replace("'", "").Replace(",", "") & "'"
            End If
            If Me.fEName.Text.Length > 0 Then
                WhereStr += " and a.fEName='" & Me.fEName.Text.Replace("'", "").Replace(",", "") & "'"
            End If
            If Me.fDeptID.Text.Length > 0 Then
                If Not Me.fDeptID.SelectedValue Is Nothing Then
                    WhereStr += " and fDeptID='" & Me.fDeptID.SelectedValue.ToString.Trim & "'"
                Else
                    WhereStr += " and fDeptID like '%" & Me.fDeptID.Text.Split("     ")(0) & "%'"
                End If
            End If
            If Me.fPosition.Text.Length > 0 Then
                WhereStr += " and fPosition='" & Me.fPosition.Text.Replace("'", "").Replace(",", "") & "'"
            End If
            If Me.fSex.Text.Length > 0 AndAlso Me.fSex.SelectedIndex <> 0 Then
                Select Case Me.fSex.SelectedIndex
                    Case 1
                        WhereStr += " and fSex =1"
                    Case 2
                        WhereStr += " and fSex =2"
                End Select
            End If
            'If Me.fStartDate.Text.Length > 0 Then
            '    WhereStr += " and fStartDate >='" & Format(Me.fStartDate.Text, "yyyy-MM-dd") & "'"
            'End If
            'If Me.fEndDate.Text.Length > 0 Then
            '    WhereStr += " and fEndDate <='" & Format(Me.fEndDate.Text, "yyyy-MM-dd") & "'"
            'End If
            If IsDate(Me.StartDate.Text) = True Then
                If Me.StartDate.Text.Length > 0 Then
                    WhereStr += " and fStartDate >='" & StartDate.Text.Trim & "' and fEndDate <='" & EndDate.Text.Trim & "'"
                Else
                    WhereStr += ""
                End If
            End If
            If IsDate(Me.EndDate.Text) = True Then
                If Me.EndDate.Text.Length > 0 Then
                    WhereStr += "  and fEndDate>='" & StartDate.Text.Trim & "' and fEndDate <='" & EndDate.Text.Trim & "'"
                Else
                    WhereStr += ""
                End If
            End If

            If IsDate(Me.StartDate.Text) = True And IsDate(Me.EndDate.Text) = True Then
                If Me.StartDate.Text.Length > 0 And Me.EndDate.Text.Length > 0 Then
                    WhereStr += " and fStartDate >='" & StartDate.Text.Trim & "'  and fEndDate>='" & StartDate.Text.Trim & "' and fEndDate <='" & EndDate.Text.Trim & "'"
                Else
                    WhereStr += ""
                End If
            End If
            Select Case str_language
                Case "zh-CHT"
                    Dim fSex As String = "case fsex when 1 then '男' when 2 then '女' else '' end as fsex"
                    sql = "select a.fCode,a.fCName,a.fEName,c.fCName as fDeptId,b.fCName as fPosition,case fsex when 1 then '男' when 2 then '女' else '' end as fsex,a.fBirthday,a.fEducation,a.fMarry,a.fCardID,a.fMobile,a.fEmail,a.fMSN,a.fQQ,a.fAddress,a.fPersonweb,a.fPhone,a.fStartDate,a.fEndDate,a.fRemark,case a.fStatus when 0 then '未停用' else '已停用' end as fStatus,case when fIsAdmin=1 then 1 else 0 end as fIsAdmin from Bsc_employee a inner join BSC_Dept b on a.fPosition=b.Id inner join BSC_Dept c on a.fDeptId=c.Id where 1=1" & WhereStr
                Case "zh-CHS"
                    Dim fSex As String = "case fsex when 1 then '男' when 2 then '女' else '' end as fsex"
                    sql = "select a.fCode,a.fCName,a.fEName,c.fCName as fDeptId,b.fCName as fPosition,case fsex when 1 then '男' when 2 then '女' else '' end as fsex,a.fBirthday,a.fEducation,a.fMarry,a.fCardID,a.fMobile,a.fEmail,a.fMSN,a.fQQ,a.fAddress,a.fPersonweb,a.fPhone,a.fStartDate,a.fEndDate,a.fRemark,case a.fStatus when 0 then '未停用' else '已停用' end as fStatus,case when fIsAdmin=1 then 1 else 0 end as fIsAdmin from Bsc_employee a inner join BSC_Dept b on a.fPosition=b.Id inner join BSC_Dept c on a.fDeptId=c.Id where 1=1" & WhereStr
                Case "en"
                    Dim fSex As String = "case fsex when 1 then 'male' when 2 then 'female' else '' end as fsex"
                    sql = "select a.fCode,a.fCName,a.fEName,c.fCName as fDeptId,b.fCName as fPosition,case fsex when 1 then '男' when 2 then '女' else '' end as fsex,a.fBirthday,a.fEducation,a.fMarry,a.fCardID,a.fMobile,a.fEmail,a.fMSN,a.fQQ,a.fAddress,a.fPersonweb,a.fPhone,a.fStartDate,a.fEndDate,a.fRemark,case a.fStatus when 0 then '未停用' else '已停用' end as fStatus,case when fIsAdmin=1 then 1 else 0 end as fIsAdmin from Bsc_employee a inner join BSC_Dept b on a.fPosition=b.Id inner join BSC_Dept c on a.fDeptId=c.Id where 1=1" & WhereStr
            End Select
            mDataset = New DataSet
            mDataset = ReturnDataset(sql)
            Me.DataGridView1.DataSource = mDataset.Tables(0)
            bFind = mDataset.Tables(0).Rows.Count > 0
            SetButton(ButtonType.Browse, bFind)
        Catch ex As Exception
            MsgBox("ActionFind:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Function BtnActionSave() As Boolean
        Try

            Dim sql As String = ""
            Dim ID As String = ""
            Dim M_Ds As New DataSet
            If ActionInitialize() = False Then Exit Function
            Dim fCode As String = Me.txtfcode.Text.Replace("'", "").Replace(",", "")
            Dim fCName As String = Me.txtfCName.Text.Replace("'", "").Replace(",", "")
            Dim fEName As String = Me.txtfEName.Text.Replace("'", "").Replace(",", "")
            Dim fSex As Integer = 0
            If Me.CBfSex.SelectedIndex = 0 OrElse Me.CBfSex.Text.Trim = "" Then
                fSex = 0
            Else
                fSex = ReturnEnumValue(GetType(E_fSex), Me.CBfSex.Text.Trim)
            End If
            Dim fPosition As String = ""
            If Not Me.txtfPosition.SelectedValue Is Nothing Then
                fPosition = Me.txtfPosition.SelectedValue.ToString()
            End If
            Dim fDeptID As String = Me.CBfDeptID.SelectedValue.ToString
            Dim fEducation As String = Me.txtfEducation.Text.Replace("'", "").Replace(",", "")
            Dim fMarry As String = Me.txtfMarry.Text.Replace("'", "").Replace(",", "")
            Dim fCardID As String = Me.txtfCardID.Text.Replace("'", "").Replace(",", "")
            Dim fMobile As String = Me.txtfMobile.Text.Replace("'", "").Replace(",", "")
            Dim fEmail As String = Me.txtfEmail.Text.Replace("'", "").Replace(",", "")
            Dim fPhone As String = Me.txtfPhone.Text.Replace("'", "").Replace(",", "")
            Dim fQQ As String = Me.txtfQQ.Text.Replace("'", "").Replace(",", "")
            Dim fMSN As String = Me.txtfMSN.Text.Replace("'", "").Replace(",", "")
            Dim fBirthday As String = Format(Me.txtfBirthday.Text.Replace("'", "").Replace(",", ""), "yyyy-MM-dd")
            Dim fPersonweb As String = Me.txtPersonweb.Text.Replace("'", "").Replace(",", "")
            Dim fAddress As String = Me.txtfAddress.Text.Replace("'", "").Replace(",", "")
            Dim fStartDate As String = Me.txtStartDate.Text.Replace("'", "").Replace(",", "")
            Dim fEndDate As String = Me.txtEndDate.Text.Replace("'", "").Replace(",", "")
            Dim fRemark As String = Me.txtfRemark.Text.Replace("'", "").Replace(",", "")
            Dim fStatus As Integer = IIf(Me.txtfStatus.Checked = False, 0, 1)
            Dim fIsAdmin As Int16 = IIf(Me.cbAdmin.Checked = False, 0, 1)


            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Then
                sql = "Insert Into BSC_Employee(fCode,fCName,fEName,fPosition,fDeptID,fSex,fBirthday,fEducation,fMarry,fCardID,fMobile,fEmail,fMSN,fQQ,fAddress,fPersonweb,fPhone,fStartDate,fEndDate,fRemark,fStatus,fIsAdmin) values('" & _
                       fCode & "','" & fCName & "','" & fEName & "','" & fPosition & "','" & fDeptID & "','" & fSex & "','" & fBirthday & "','" & fEducation & "','" & fMarry & "','" & fCardID & "','" & fMobile & "','" & _
                       fEmail & "','" & fMSN & "','" & fQQ & "','" & fAddress & "','" & fPersonweb & "','" & fPhone & "','" & fStartDate & "','" & fEndDate & "','" & fRemark & "'," & fStatus & "," & fIsAdmin & "); "
                sql += "SELECT @@IDENTITY as ID"
                M_Ds = ReturnDataset(sql)
                ID = M_Ds.Tables(0).Rows(0).Item(0)
                AddtoDataSet(ID, fCode, fCName, fEName, txtfPosition.Text.Trim, Me.CBfDeptID.Text.Trim, fSex, fBirthday, fEducation, fMarry, fCardID, fMobile, fEmail, fMSN, fQQ, fAddress, fPersonweb, fPhone, fStartDate, fEndDate, fRemark, fStatus, fIsAdmin)
            ElseIf ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
                sql = "Update BSC_Employee Set fCName='" & fCName & "',fEName='" & fEName & "',fPosition='" & fPosition & "',fDeptId='" & fDeptID & "',fSex='" & fSex & "',fBirthday='" & fBirthday & "',fEducation='" & fEducation & "',fMarry='" & fMarry & _
                      "',fCardID='" & fCardID & "',fMobile='" & fMobile & "',fEmail='" & fEmail & "',fMSN='" & fMSN & "',fQQ='" & fQQ & "',fAddress='" & fAddress & "',fPersonweb='" & fPersonweb & "',fPhone='" & fPhone & "',fStartDate='" & fStartDate & "',fEndDate='" & fEndDate & "',fRemark='" & _
                      fRemark & "',fStatus=" & fStatus & ",fIsAdmin=" & fIsAdmin & " where fCode='" & fCode & "'"
                ReturnObject(sql)
                EditToDataSet(fCode, fCName, fEName, txtfPosition.Text.Trim, Me.CBfDeptID.Text.Trim, fSex, fBirthday, fEducation, fMarry, fCardID, fMobile, fEmail, fMSN, fQQ, fAddress, fPersonweb, fPhone, fStartDate, fEndDate, fRemark, fStatus, fIsAdmin)
            End If
            MsgBox(IIf(ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd, My.Resources.AddSuccess, My.Resources.EditSuccess), MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
            Me.DataGridView1.DataSource = mDataset.Tables(0)
            ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp
            SetCtlEnable(False)
            bFind = True
            SetButton(ButtonType.Browse, True)
            MainFrom.ToolStripFind.Enabled = False
            MainFrom.ToolStripFilter.Enabled = False
            Return True
        Catch ex As Exception
            MsgBox("ActionSave:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Private Sub AddtoDataSet(ByVal ID As Integer, ByVal fCode As String, ByVal fCName As String, ByVal fEName As String, ByVal fPosition As String, ByVal fDeptId As String, ByVal fSex As String, ByVal fBirthday As String, _
                             ByVal fEducation As String, ByVal fMarry As String, ByVal fCardID As String, ByVal fMobile As String, ByVal fEmail As String, ByVal fMSN As String, ByVal fQQ As String, ByVal fAddress As String, ByVal fPersonweb As String, _
                             ByVal fPhone As String, ByVal fStartDate As String, ByVal fEndDate As String, ByVal fRemark As String, ByVal fStatus As Integer, ByVal fIsAdmin As Int16)
        Try
            'If mDataset Is Nothing Then Exit Sub
            Dim mRow As DataRow = mDataset.Tables(0).NewRow
            mRow("fCode") = fCode
            mRow("fCName") = fCName
            mRow("fEName") = fEName
            mRow("fPosition") = fPosition
            mRow("fDeptId") = fDeptId
            Select Case str_language
                Case "zh-CHT"
                    If fSex = 0 Then
                        mRow("fSex") = "男"
                    Else
                        mRow("fSex") = "女"
                    End If
                Case "zh-CHS"
                    If fSex = 0 Then
                        mRow("fSex") = "男 "
                    Else
                        mRow("fSex") = "女"
                    End If
                Case "en"
                    If fSex = 0 Then
                        mRow("fSex") = "male"
                    Else
                        mRow("fSex") = "female"
                    End If
            End Select
            mRow("fBirthday") = fBirthday
            mRow("fEducation") = fEducation
            mRow("fMarry") = fMarry
            mRow("fCardID") = fCardID
            mRow("fMobile") = fMobile
            mRow("fEmail") = fEmail
            mRow("fMSN") = fMSN
            mRow("fQQ") = fQQ
            mRow("fAddress") = fAddress
            mRow("fPersonweb") = fPersonweb
            mRow("fPhone") = fPhone
            mRow("fStartDate") = fStartDate
            mRow("fEndDate") = fEndDate
            mRow("fRemark") = fRemark
            If fStatus = 0 Then
                mRow("fStatus") = "未停用"
            Else
                mRow("fStatus") = "已停用"
            End If

            If fIsAdmin = 1 Then
                mRow("fIsAdmin") = 1
            Else
                mRow("fIsAdmin") = 0

            End If

            mDataset.Tables(0).Rows.Add(mRow)
            mDataset.AcceptChanges()
        Catch ex As Exception
            MsgBox("AddtoDataSet:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub EditToDataSet(ByVal fCode As String, ByVal fCName As String, ByVal fEName As String, ByVal fPosition As String, ByVal fDeptId As String, ByVal fSex As String, ByVal fBirthday As String, _
                             ByVal fEducation As String, ByVal fMarry As String, ByVal fCardID As String, ByVal fMobile As String, ByVal fEmail As String, ByVal fMSN As String, ByVal fQQ As String, ByVal fAddress As String, ByVal fPersonweb As String, _
                             ByVal fPhone As String, ByVal fStartDate As String, ByVal fEndDate As String, ByVal fRemark As String, ByVal fStatus As Integer, ByVal fIsAdmin As Int16)
        Try

            Dim Rows() As DataRow = mDataset.Tables(0).Select("fcode='" & fCode & "'")
            If Rows.Length > 0 Then
                For Each mRow As DataRow In Rows
                    mRow("fCode") = fCode
                    mRow("fCName") = fCName
                    mRow("fEName") = fEName
                    mRow("fPosition") = fPosition
                    mRow("fDeptId") = fDeptId
                    Select Case str_language
                        Case "zh-CHT"
                            If fSex = 0 Then
                                mRow("fSex") = "男"
                            Else
                                mRow("fSex") = "女"
                            End If
                        Case "zh-CHS"
                            If fSex = 0 Then
                                mRow("fSex") = "男 "
                            Else
                                mRow("fSex") = "女"
                            End If
                        Case "en"
                            If fSex = 0 Then
                                mRow("fSex") = "male"
                            Else
                                mRow("fSex") = "female"
                            End If
                    End Select
                    mRow("fBirthday") = fBirthday
                    mRow("fEducation") = fEducation
                    mRow("fMarry") = fMarry
                    mRow("fCardID") = fCardID
                    mRow("fMobile") = fMobile
                    mRow("fEmail") = fEmail
                    mRow("fMSN") = fMSN
                    mRow("fQQ") = fQQ
                    mRow("fAddress") = fAddress
                    mRow("fPersonweb") = fPersonweb
                    mRow("fPhone") = fPhone
                    mRow("fStartDate") = fStartDate
                    mRow("fEndDate") = fEndDate
                    mRow("fRemark") = fRemark
                    If fStatus = 0 Then
                        mRow("fStatus") = "未停用"
                    Else
                        mRow("fStatus") = "已停用"
                    End If

                    If fIsAdmin = 1 Then
                        mRow("fIsAdmin") = 1
                    Else
                        mRow("fIsAdmin") = 0

                    End If
                Next
            End If
            mDataset.AcceptChanges()
        Catch ex As Exception
            MsgBox("EditToDataSet:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Function DeleteFromDataBase(ByVal fCode As String) As Boolean
        Try
            Dim sql As String = ""
            sql = "Delete from Bsc_employee where fCode='" & fCode & "'"
            ReturnObject(sql)
            Return True
        Catch ex As Exception
            MsgBox("DeleteFromDataBase:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Private Function DeleteFromDataset(ByVal fCode As String) As Boolean
        Try
            If mDataset Is Nothing Then Exit Function
            Dim Rows() As DataRow = mDataset.Tables(0).Select("fCode='" & fCode & "'")
            If Rows.Length > 0 Then
                For Each mRow As DataRow In Rows
                    mDataset.Tables(0).Rows.Remove(mRow)
                Next
            End If
            mDataset.AcceptChanges()
            Return True
        Catch ex As Exception
            MsgBox("DeleteFromDataset:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function
    Private Sub FillText(ByVal ID As String)
        Try
            If mDataset Is Nothing Then Exit Sub
            Dim Rows() As DataRow = mDataset.Tables(0).Select("fCode='" & ID & "'")
            If Not Rows Is Nothing Then
                For Each mRow As DataRow In Rows
                    Me.txtfcode.Text = mRow("fCode") & ""
                    Me.txtfCName.Text = mRow("fCName") & ""
                    Me.CBfDeptID.Text = mRow("fDeptID") & ""
                    'Me.CBfDeptID.Text = ""
                    'Me.CBfDeptID.SelectedText = mRow("fDeptID") & ""
                    Me.txtfEName.Text = mRow("fEName") & ""
                    Me.txtfPosition.Text = mRow("fPosition") & ""
                    'Me.CBfSex.SelectedText = mRow("fSex") & ""
                    If [Enum].IsDefined(GetType(E_fSex), mRow("fSex") & "") = True Then
                        Me.CBfSex.Text = mRow("fSex") & ""
                    Else
                        Me.CBfSex.SelectedIndex = 0
                    End If
                    Me.txtfBirthday.Value = Convert.ToDateTime(mRow("fBirthday") & "")
                    Me.txtfEducation.Text = mRow("fEducation") & ""
                    Me.txtfMarry.Text = mRow("fMarry") & ""
                    Me.txtfCardID.Text = mRow("fCardID") & ""
                    Me.txtfMobile.Text = mRow("fMobile") & ""
                    Me.txtfEmail.Text = mRow("fEmail") & ""
                    Me.txtfMSN.Text = mRow("fMSN") & ""
                    Me.txtfQQ.Text = mRow("fQQ") & ""
                    Me.txtfAddress.Text = mRow("fAddress") & ""
                    Me.txtPersonweb.Text = mRow("fPersonweb") & ""
                    Me.txtfPhone.Text = mRow("fPhone") & ""
                    Me.txtStartDate.Text = mRow("fStartDate") & ""
                    Me.txtEndDate.Text = mRow("fEndDate") & ""
                    Me.txtfRemark.Text = mRow("fRemark") & ""
                    If mRow("fStatus") & "" = "未停用" Then
                        Me.txtfStatus.Checked = False
                    Else
                        Me.txtfStatus.Checked = True
                    End If
                    IsFind = True

                    If mRow("fIsAdmin") & "" = "1" Then
                        Me.cbAdmin.Checked = True
                    Else
                        Me.cbAdmin.Checked = False

                    End If
                Next
            Else
                Me.txtfcode.Text = ""
                Me.txtfCName.Text = ""
                Me.CBfDeptID.Text = ""
                Me.txtfEName.Text = ""
                Me.txtfPosition.Text = ""
                Me.CBfSex.SelectedIndex = 0
                Me.txtfBirthday.Text = ServerDate
                Me.txtfEducation.Text = ""
                Me.txtfMarry.Text = ""
                Me.txtfCardID.Text = ""
                Me.txtfMobile.Text = ""
                Me.txtfEmail.Text = ""
                Me.txtfMSN.Text = ""
                Me.txtfQQ.Text = ""
                Me.txtfAddress.Text = ""
                Me.txtPersonweb.Text = ""
                Me.txtfPhone.Text = ""
                Me.txtfRemark.Text = ""
                Me.cbAdmin.Checked = False

            End If
        Catch ex As Exception
            MsgBox("FillText:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub GetToolEnable()
        Try
            With MainFrom
                .ToolStripAdd.Enabled = AddEnable
                .ToolStripEdit.Enabled = EditEnable
                .ToolStripDelete.Enabled = DeleteEnable
                .ToolStripPrint.Enabled = PrintEnable
                .ToolStripImport.Enabled = ImportEnable
                .ToolStripExport.Enabled = ExportEnable
                .ToolStripFind.Enabled = FindEnable
                .ToolStripFilter.Enabled = True
                .ToolStripCheck.Enabled = False
                .ToolStripUnCheck.Enabled = False
                .ToolStripComplete.Enabled = False
                .AddToolStripMenuItem.Enabled = .ToolStripAdd.Enabled
                .Edit1ToolStripMenuItem.Enabled = .ToolStripEdit.Enabled
                .DelToolStripMenuItem.Enabled = .ToolStripDelete.Enabled
                .SaveToolStripMenuItem.Enabled = .ToolStripSave.Enabled
                .CancelToolStripMenuItem.Enabled = .ToolStripCancel.Enabled
                .PrintToolStripMenuItem.Enabled = .ToolStripPrint.Enabled
                .ExportToolStripMenuItem.Enabled = .ToolStripImport.Enabled
                .ImportToolStripMenuItem.Enabled = .ToolStripExport.Enabled
                .FilterToolStripMenuItem.Enabled = .ToolStripFilter.Enabled
            End With

        Catch ex As Exception
            MsgBox("GetToolEnable:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    ''' <summary>
    ''' 設置按鈕狀態
    ''' </summary>
    ''' <param name="type"></param>
    ''' <remarks></remarks>
    Private Sub SetButton(ByVal type As ButtonType, ByVal IsFind As Boolean)
        Try
            Select Case type
                Case ButtonType.Add
                    With MainFrom
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = False
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = False
                        .ToolStripFilter.Enabled = False
                        .ToolStripFind.Enabled = False

                    End With

                Case ButtonType.Browse
                    With MainFrom
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind
                        .ToolStripDelete.Enabled = IsFind
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind
                        .ToolStripLast.Enabled = IsFind
                        .ToolStripNext.Enabled = IsFind
                        .ToolStripPrivous.Enabled = IsFind
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Cancel
                    With MainFrom
                        .ToolStripAdd.Enabled = True
                        .ToolStripEdit.Enabled = IsFind
                        .ToolStripDelete.Enabled = IsFind
                        .ToolStripSave.Enabled = False
                        .ToolStripCancel.Enabled = False
                        .ToolStripFirst.Enabled = IsFind
                        .ToolStripLast.Enabled = IsFind
                        .ToolStripNext.Enabled = IsFind
                        .ToolStripPrivous.Enabled = IsFind
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = True
                        .ToolStripPrint.Enabled = IsFind
                        .ToolStripFilter.Enabled = True

                    End With

                Case ButtonType.Edit
                    With MainFrom
                        .ToolStripAdd.Enabled = False
                        .ToolStripEdit.Enabled = False
                        .ToolStripDelete.Enabled = False
                        .ToolStripSave.Enabled = True
                        .ToolStripCancel.Enabled = True
                        .ToolStripFirst.Enabled = False
                        .ToolStripLast.Enabled = False
                        .ToolStripNext.Enabled = False
                        .ToolStripPrivous.Enabled = False
                        .ToolStripExport.Enabled = IsFind
                        .ToolStripImport.Enabled = False
                        .ToolStripPrint.Enabled = False
                        .ToolStripFilter.Enabled = False
                        .ToolStripFind.Enabled = False
                    End With

            End Select
            With MainFrom
                .ToolStripCheck.Enabled = False
                .ToolStripUnCheck.Enabled = False
                .ToolStripComplete.Enabled = False
            End With
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try

    End Sub

#End Region
#Region "Control Events"


    Private Sub Frm_BSCStaff_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If mDataset Is Nothing Then
                mDataset = New DataSet
                mDataset = BuildDataset()
            End If
            If str_language.ToString.Trim.Length <= 0 Then
                str_language = ReadSystemlanguage()
            End If
            If str_language.ToString.ToString.Length <= 0 Then
                str_language = Msg.Systemdefaultlanguage
            End If
            Select Case str_language
                Case "zh-CHT"
                    str_language = "zh-CHT"
                    Captionstr = Captionstr_CHT
                Case "zh-CHS"
                    str_language = "zh-CHS"
                    Captionstr = Captionstr_CHS
                Case "en"
                    str_language = "en"
                    Captionstr = Captionstr_en
                Case "english"
                    str_language = "en"
                    Captionstr = Captionstr_en
            End Select
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(App.str_language)
            DataBindGrid(Me.DataGridView1, Captionstr)
            BindGridCaption(Me.DataGridView1, BindHashTable(Captionstr))
            FormatDataGridView(Me.DataGridView1)
            SetGridCaptionVisible(Me.DataGridView1, Fields, "Frm_BSCStaff")
            LoadComBox(Me.fSex)
            LoadComBox(Me.CBfSex)
            LoadDeptID()
            ClearText()
            SetCtlEnable(False)
            Me.BtnFind.Enabled = FindEnable
            LoadBool = True
        Catch ex As Exception
            MsgBox("Frm_BSCStaff_Load:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub TabControl1_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
        Try
            If Not Me.TabControl1.SelectedTab Is Nothing Then
                Select Case Me.TabControl1.SelectedIndex
                    Case 0
                        'IsFilter = True
                        'IsExport = True
                        'MainFrom.ToolStripFind.Enabled = True
                        'MainFrom.ToolStripFilter.Enabled = True
                        'MainFrom.ToolStripImport.Enabled = True
                    Case 1
                        If mDataset.Tables(0).Rows.Count <= 0 Then
                            ClearText()
                        Else
                            Dim fCode As String = Me.DataGridView1.CurrentRow.Cells("fCode").Value
                            If fCode.Length > 0 Then
                                FillText(fCode)
                            End If
                        End If
                        'MainFrom.ToolStripFind.Enabled = False
                        'MainFrom.ToolStripFilter.Enabled = False
                        'MainFrom.ToolStripImport.Enabled = False
                End Select
                'GetToolEnable()
            End If
        Catch ex As Exception
            MsgBox("TabControl1_Selected:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        Try
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Or ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then
                e.Cancel = True
            End If
        Catch ex As Exception
            MsgBox("TabControl1_Selecting:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        Try
            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
        Catch ex As Exception
            MsgBox("DataGridView1_DoubleClick:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
        Try
            Select Case e.KeyCode
                Case Keys.Up
                    ActionGoPrevious()
                Case Keys.Down
                    ActionGoNext()
                Case Keys.Delete
                    ActionDelete()
            End Select

        Catch ex As Exception
            MsgBox("DataGridView1_KeyDown:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
        Try
            If Me.DataGridView1.RowCount > 0 Then
                If Me.DataGridView1.CurrentRow.Index = 0 Then
                    MainFrom.ToolStripFirst.Enabled = False
                    MainFrom.ToolStripPrivous.Enabled = False
                    MainFrom.ToolStripNext.Enabled = True
                    MainFrom.ToolStripLast.Enabled = True
                ElseIf Me.DataGridView1.CurrentRow.Index > 0 And Me.DataGridView1.CurrentRow.Index < Me.DataGridView1.RowCount - 1 Then
                    MainFrom.ToolStripFirst.Enabled = True
                    MainFrom.ToolStripPrivous.Enabled = True
                    MainFrom.ToolStripNext.Enabled = True
                    MainFrom.ToolStripLast.Enabled = True
                ElseIf Me.DataGridView1.CurrentRow.Index = Me.DataGridView1.RowCount - 1 Then
                    MainFrom.ToolStripFirst.Enabled = True
                    MainFrom.ToolStripPrivous.Enabled = True
                    MainFrom.ToolStripNext.Enabled = False
                    MainFrom.ToolStripLast.Enabled = False
                End If
            End If
        Catch ex As Exception
            MsgBox("DataGridView1_MouseClick" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub fCode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles fCode.KeyDown, fCName.KeyDown, fEName.KeyDown, fEndDate.KeyDown, fPosition.KeyDown, fStartDate.KeyDown
        Try
            If e.KeyCode = Keys.Shift Then
                e.Handled = True
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("+{TAB}")
                    SendKeys.Send("{F4}")
                End If
            Else
                Select Case e.KeyCode
                    Case Keys.Enter
                        e.Handled = True
                        SendKeys.Send("{TAB}")
                        SendKeys.Send("{F4}")
                    Case Keys.Delete
                        If sender.name = "fStartDate" Then
                            Me.fStartDate.Text = ""
                        End If
                End Select
            End If
        Catch ex As Exception
            MsgBox("fCode_KeyDown:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub txtfcode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtfcode.KeyDown, txtfAddress.KeyDown, txtfBirthday.KeyDown, txtfCardID.KeyDown, txtfCName.KeyDown, txtfEducation.KeyDown, txtfEmail.KeyDown, txtfEName.KeyDown, txtfEndDate.KeyDown, txtfMarry.KeyDown, txtfMobile.KeyDown, txtfMSN.KeyDown, txtfPhone.KeyDown, txtfQQ.KeyDown, txtfRemark.KeyDown, txtfStartDate.KeyDown, txtPersonweb.KeyDown, CBfSex.KeyDown, CBfDeptID.KeyDown, txtfPosition.KeyDown
        Try
            If e.KeyCode = Keys.Shift Then
                e.Handled = True
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("+{TAB}")
                    SendKeys.Send("{F4}")
                End If
            Else
                Select Case e.KeyCode
                    Case Keys.Enter
                        e.Handled = True
                        If sender.name = "txtfPosition" Then
                            Me.txtfEducation.Focus()
                            SendKeys.Send("{TAB}")
                        Else
                            SendKeys.Send("{TAB}")
                            SendKeys.Send("{F4}")
                        End If
                End Select
            End If
        Catch ex As Exception
            MsgBox("txtfcode_KeyDown:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub BtnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnFind.Click
        Try
            MainFrom.ToolStripFind_Click(Nothing, Nothing)
        Catch ex As Exception
            MsgBox("BtnFind_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub BtnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            MainFrom.ToolStripSave_Click(Nothing, Nothing)
        Catch ex As Exception
            MsgBox("BtnOK_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            MainFrom.ToolStripCancel_Click(Nothing, Nothing)
        Catch ex As Exception
            MsgBox("BtnCancel_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub CBfDeptID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBfDeptID.SelectedIndexChanged
        Try
            If ActionHelp = IDServer.IDServer.ActionBtn.ActionAdd Or ActionHelp = IDServer.IDServer.ActionBtn.ActionEdit Then

                Dim sql As String
                Dim PostionDs As New DataSet
                Dim fParentID As String = ""
                If Not Me.CBfDeptID.SelectedValue Is Nothing Then
                    fParentID = Me.CBfDeptID.SelectedValue.ToString & ""
                End If
                sql = "SELECT * FROM DBO.BSC_DEPT where fParentID='" & fParentID & "'"
                PostionDs = ReturnDataset(sql)
                Me.txtfPosition.DataSource = PostionDs.Tables(0)
                Me.txtfPosition.DisplayMember = "fCName"
                Me.txtfPosition.ValueMember = "ID"

            End If
        Catch ex As Exception
            MsgBox("CBfDeptID_SelectedIndexChanged:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub CBfDeptID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBfDeptID.TextChanged
        Try
            If LoadBool = False Then Exit Sub

            If ActionHelp = IDServer.IDServer.ActionBtn.ActionHelp Then

                Dim sql As String
                Dim PostionDs As New DataSet
                Dim fParentID As String = ""
                If Not Me.CBfDeptID.SelectedValue Is Nothing Then
                    fParentID = Me.CBfDeptID.SelectedValue.ToString & ""
                End If
                sql = "SELECT * FROM DBO.BSC_DEPT where fParentID='" & fParentID & "'"
                PostionDs = ReturnDataset(sql)

                Me.txtfPosition.DisplayMember = "fCName"
                Me.txtfPosition.ValueMember = "ID"
                Me.txtfPosition.DataSource = PostionDs.Tables(0)

            End If
        Catch ex As Exception
            MsgBox("CBfDeptID_TextChanged:" & ex.ToString & ex.StackTrace, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, Msg.CompanyName)
        End Try
    End Sub

    Private Sub txtfStartDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtfStartDate.ValueChanged
        Me.txtStartDate.Text = Me.txtfStartDate.Text
    End Sub

    Private Sub txtfEndDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtfEndDate.ValueChanged
        Me.txtEndDate.Text = Me.txtfEndDate.Text
    End Sub

    Private Sub fStartDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles fStartDate.ValueChanged
        Me.StartDate.Text = Me.fStartDate.Text
    End Sub

    Private Sub fEndDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles fEndDate.ValueChanged
        Me.EndDate.Text = Me.fEndDate.Text
    End Sub

#End Region

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Private Sub BtnOK_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Try
            MainFrom.ToolStripSave_Click(Nothing, Nothing)
        Catch ex As Exception
            MsgBox("BtnOK_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub BtnCancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Try
            MainFrom.ToolStripCancel_Click(Nothing, Nothing)
        Catch ex As Exception
            MsgBox("BtnCancel_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
    Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub


    Private Sub Label32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label32.Click

    End Sub

    Private Sub Label29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label29.Click

    End Sub
End Class
